package br.com.lambdacore.collection;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.TreeMap;
import java.util.WeakHashMap;

import br.com.lambdacore.validator.Validator;

public class MapUtil {

	private MapUtil() {
		throw new AssertionError();
	}

	@SuppressWarnings({
			"rawtypes", "unchecked"
	})
	public static Map fillMap(Map map, Collection keys, Collection values) {
		if (Validator.is(keys).sizeNotEquals(values)) {
			throw new IllegalArgumentException(
					"Collection key and value not size match.");
		}
		LinkedList keyList = CollectionsUtil.linkedList(keys);
		LinkedList valueList = CollectionsUtil.linkedList(values);
		for (Object key : keyList) {
			map.put(key, valueList.poll());
		}
		return map;
	}

	public static <K, V> HashMap<K, V> hashMap() {
		return new HashMap<K, V>();
	}

	public static <K, V> LinkedHashMap<K, V> linkedHashMap() {
		return new LinkedHashMap<K, V>();
	}

	public static <K, V> TreeMap<K, V> treeMap() {
		return new TreeMap<K, V>();
	}

	public static <K, V> WeakHashMap<K, V> weakHashMap() {
		return new WeakHashMap<K, V>();
	}

}
